<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

include('fonctionSQL.php');

//On verifie que la variable action existe
if (isset($_POST['action'])) {
//On echape les variables pour pouvoir les mettre dans une requette SQL
    $action = mysql_real_escape_string($_POST['action']);

    if ($action == "ajouterQuizz") {

//On récupére les variables
        if (isset($_POST['idPoint'], $_POST['nomQ'], $_POST['nbQuestion'], $_POST['nbReponse'], $_POST['question'], $_POST['imgQ'], $_POST['reponse'], $_POST['imgR'], $_POST['reponseC'], $_POST['type'])) {
//On echape les variables pour pouvoir les mettre dans une requette SQL
            $idPoint = mysql_real_escape_string($_POST['idPoint']);
            $nomQuizz = mysql_real_escape_string($_POST['nomQ']);
            $nbQuestion = mysql_real_escape_string($_POST['nbQuestion']);
            $nbReponse = mysql_real_escape_string($_POST['nbReponse']);
            $type = mysql_real_escape_string($_POST['type']);

            $question = json_decode($_POST['question'], true);
            $imgQ = json_decode($_POST['imgQ'], true);
            $reponse = json_decode($_POST['reponse'], true);
            $imgR = json_decode($_POST['imgR'], true);
            $correct = json_decode($_POST['reponseC'], true);


            $message = ajoutQuizz($idPoint, $nomQuizz, $nbQuestion, $nbReponse, $type, $question, $imgQ, $reponse, $imgR, $correct);
        }
    } else if ($action == "ajouterTempsL") {

//On récupére les variables
        if (isset($_POST['idPoint'], $_POST['arc'], $_POST['duree'], $_POST['type'])) {

//On echape les variables pour pouvoir les mettre dans une requette SQL
            $idPoint = mysql_real_escape_string($_POST['idPoint']);
            $arc = mysql_real_escape_string($_POST['arc']);
            $duree = mysql_real_escape_string($_POST['duree']);
            $type = mysql_real_escape_string($_POST['type']);

            $message = ajouterTL($idPoint, $type, $duree, $arc);
        }
    } else if ($action == "ajouterCF") {

//On récupére les variables
        if (isset($_POST['idPoint'], $_POST['arc'], $_POST['precision'], $_POST['type'])) {

//On echape les variables pour pouvoir les mettre dans une requette SQL
            $idPoint = mysql_real_escape_string($_POST['idPoint']);
            $arc = mysql_real_escape_string($_POST['arc']);
            $precision = mysql_real_escape_string($_POST['precision']);
            $type = mysql_real_escape_string($_POST['type']);

            $message = ajouterCF($idPoint, $type, $precision, $arc);
        }
    } else if ($action == "afficherActivite") {
//On récupére les variables
        if (isset($_POST['idPoint'])) {
//On echape les variables pour pouvoir les mettre dans une requette SQL
            $idPoint = mysql_real_escape_string($_POST['idPoint']);

            $message = afficherActivite($idPoint);
        }
    } else if ($action == "supprimerActivite") {
//On récupére les variables
        if (isset($_POST['idActivite'])) {
//On echape les variables pour pouvoir les mettre dans une requette SQL
            $idActivite = mysql_real_escape_string($_POST['idActivite']);

            $message = supprimerActivite($idActivite);
        }
    } else if ($action == "recupCF") {
        if (isset($_POST['id'])) {
            $idActivite = mysql_real_escape_string($_POST['id']);
            $message = recupCF($idActivite);
        }
    } else if ($action == "recupTL") {
        if (isset($_POST['id'])) {
            $idActivite = mysql_real_escape_string($_POST['id']);
            $message = recupTL($idActivite);
        }
    } else if ($action == "modifierTL") {
        if (isset($_POST['id'], $_POST['duree'], $_POST['arc'])) {
            $idActivite = mysql_real_escape_string($_POST['id']);
            $duree = mysql_real_escape_string($_POST['duree']);
            $arc = mysql_real_escape_string($_POST['arc']);

            echo $arc . $duree;

            $message = modifierTL($idActivite, $duree, $arc);
        }
    } else if ($action == "modifierCF") {
        if (isset($_POST['id'], $_POST['precision'], $_POST['arc'])) {
            $idActivite = mysql_real_escape_string($_POST['id']);
            $precision = mysql_real_escape_string($_POST['precision']);
            $arc = mysql_real_escape_string($_POST['arc']);

            $message = modifierCF($idActivite, $precision, $arc);
        }
    }
}
?>
